#include "types.h"
#include "user.h"
#include "semaphore.h"

static void * func();

struct semaphore* semaphore;

int
main(int argc, char *argv[])
{
	int t=0;
	int i;
	void *pg;
	void* ret;

	semaphore = semaphore_create(4);

	for (i = 0; i<10;i++){
		pg = malloc(1024);
		t = thread_create(&func, pg, 1024);
	}
	thread_join(t, &ret);
	exit();
}

static void* func(){
	int j;
	sem_down(semaphore);
	for (j=0;j<50;j++)
		printf(2, "Process %d Thread %d is running\n", thread_getProcId(), thread_getid());
	sem_up(semaphore);
	thread_exit((void *) thread_getid());
	return 0;
}